package com.cenntro.oss.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cenntro.common.base.BaseController;
import com.cenntro.common.util.ConvertorUtils;
import com.cenntro.common.util.result.Result;
import com.cenntro.oss.model.dbo.DevCarDO;
import com.cenntro.oss.model.vo.DevCarVO;
import com.cenntro.oss.service.DevCarService;
import com.cenntro.oss.valid.Valid;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * <p>
 * 车型表 前端控制器
 * </p>
 *
 * @author
 * @since 2018-09-17
 */

@Api(value = "车型管理", tags = { "车型管理" })
@RestController
@RequestMapping("/car")
public class DevCarModelController extends BaseController {

	@Resource
	private DevCarService devCarService;
	
	/**
	 * 
	* @Title list
	* @Description 车型列表
	* @param 
	* @return  
	* @throws
	 */
	@ApiOperation(value = "车型列表", notes = "车型列表")
	@RequestMapping("/listype")
	public Result list() {
		List<DevCarDO> list = devCarService.selectPage(null);
		return Result.ok(list);
	}
	
	
	/**
	 * 
	* @Title insert
	* @Description 车型新增
	* @param carmodel
	* @return  
	* @throws
	 */
	@ApiOperation(value = "车型新增", notes = "车型新增")
	@RequestMapping("/insert")
	public Result insert(@Validated DevCarVO carmodel) {
		DevCarDO carModelDO = ConvertorUtils.deepConvert(carmodel, DevCarDO.class);
		devCarService.insert(carModelDO);
		return Result.ok();
	}

	/**
	 * 
	* @Title delete
	* @Description 车型删除
	* @param carmodel
	* @return  
	* @throws
	 */
	@ApiOperation(value = "车型删除", notes = "车型删除")
	@RequestMapping("/delete")
	public Result delete(@Validated(value = Valid.update.class) DevCarVO carmodel) {
		DevCarDO carModelDO = ConvertorUtils.deepConvert(carmodel, DevCarDO.class);
		carModelDO.setStatus(0);
		devCarService.update(carModelDO);
		return Result.ok();
	}
	
	/**
	 * 
	* @Title update
	* @Description 车型修改
	* @param carmodel
	* @return  
	* @throws
	 */
	@ApiOperation(value = "车型修改", notes = "车型修改")
	@RequestMapping("/update")
	public Result update(@Validated(value = Valid.update.class) DevCarVO carmodel) {
		DevCarDO carModelDO = ConvertorUtils.deepConvert(carmodel, DevCarDO.class);
		devCarService.update(carModelDO);
		return Result.ok();
	}
	
}
